from os import path
from json import (load as jsonload, dump as jsondump)
import PySimpleGUI as sg

SETTINGS_FILE = r'./settings_file.cfg'
DEFAULT_SETTINGS = {'LpsCookie': '', 'QfsCookie': ''}

def load_settings(settings_file):
    try:
        with open(settings_file, 'r') as f:
            settings = jsonload(f)
    except Exception as e:
        sg.popup_quick_message(f"未找到登陆信息文件将为自动创建一个默认配置.....", keep_on_top=True, background_color='red', text_color='white')
        settings = DEFAULT_SETTINGS
        save_settings(settings_file, settings)
    return settings


def save_settings(settings_file: str, settings: dict):
    with open(settings_file, 'w') as f:
        jsondump(settings, f)


